home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / utilities / guide / masterguide12a.lha / masterguide.rexx < prev   
Encoding:
OS/2 REXX Batch file  |  1994-09-23  |  14.0 KB  |  416 lines

  1. /****************************************************************************/
  2. /*                          Master-Guide                                    */
  3. /*                   $VER: Master-Guide 1.2b (07.09.94)                     */
  4. /*                                                                          */
  5. /* This program examines a directory to find AmigaGuide files. The guides   */
  6. /* found will be put in one big guide, which are linked to the original     */
  7. /* docs, it can work through subdirectories in a recursive way              */
  8. /*                                                                          */
  9. /* Bugs know in v1.1c: Will put directories in, which have no subdirs, or   */
  10. /*                     Guides                                               */
  11. /*                                                                          */
  12. /* Author:    Kenneth Fribert   FidoNet: 2:235/317.0                        */
  13. /*                              email:   kfribert@scala.ping.dk             */
  14. /*                                       kfribert@kfribert.adsp.sub.org     */
  15. /*                                       kensaga@diku.dk                    */
  16. /*                                                                          */
  17. /*  This program is postcardware/emailware, what suits you the best, this   */
  18. /*  means that if you use it, you are obliged to send me a postcard or at   */
  19. /*  least an email. Gifts, cars etc. are welcome, but hey, this program     */
  20. /*  Aren't that big a deal :-)                                              */
  21. /*                                                                          */
  22. /* The program has the following arguments:                                 */
  23. /* PATH/M ALL/S OUT=OUTPUT/K                                                */
  24. /* Where Path is the place(s) to search for guides, 'ALL' is whether or not */
  25. /* it should work recursive, output is where to put the resulting guide and */
  26. /* the filename.                                                            */
  27. /****************************************************************************/
  28.  
  29. Options Results
  30.  
  31. Parse Arg Argumenter
  32. Signal On BREAK_C
  33. /*Signal On SYNTAX*/
  34.  
  35. /****************************************************************************/
  36. /* Make arexx-port                                                          */
  37. /* Check that no other MasterGuide's are working                            */
  38. /****************************************************************************/
  39.  
  40. If Show(P,'MasterGuide')~=0 Then
  41. Do
  42.    Say ('MasterGuide is already working')
  43.    Exit 5
  44. End
  45.  
  46. If ~Exists('libs:rexxsupport.library') Then
  47. Do
  48.    Say 'RexxSupport.library is needed, please install it in your libs: dir'
  49.    Exit 10
  50. End
  51.  
  52. If ~Show('L','rexxsupport.library') Then
  53.    Call AddLib('rexxsupport.library',0,-30,0)
  54.  
  55. Call OpenPort('MasterGuide')
  56. Headerfile='Rexx:Guide.Head'
  57. EndFile='Rexx:Guide.End'
  58.  
  59. If ~Exists('libs:RexxDosSupport.library') Then
  60. Do
  61.    Say 'RexxDosSupport.library is needed, please install it in your libs: dir'
  62.    Exit 10
  63. End
  64.  
  65. If ~Show('L','RexxDosSupport.library') Then
  66.    Call AddLib('RexxDosSupport.library',0,-30)
  67.  
  68.  
  69. If ~Show('L','datatypes.library') Then
  70. Do
  71.    Call AddLib('datatypes.library',0,-30,39)
  72. End
  73. UseDT=Exists('libs:datatypes.library')
  74.  
  75. Template='PATH/M,ALL/S,TXT/S,OUT/K'
  76. Call ReadArgs(argumenter,template,"input.")
  77. If input.path.0=? Then
  78. Do
  79.    Say Template
  80.    Exit 0
  81. End
  82.  
  83. If input.path.count=0 Then
  84. Do
  85.    Say 'Search path for AmigaGuide files are missing!'
  86.    Exit 10
  87. End
  88.  
  89. If input.out='INPUT.OUT' Then
  90.    input.out='Ram:MasterGuide'
  91.  
  92.  
  93. /****************************************************************************/
  94. /* Main program                                                             */
  95. /****************************************************************************/
  96. Do
  97.    Call Header(input.out,HeaderFile)
  98.    Call Multiple()
  99.    Call EndGuide(EndFile)
  100.    Call Closeport('MasterGuide')
  101. End
  102. Exit 0
  103.  
  104.  
  105.  
  106. /****************************************************************************/
  107. /* If multiple drawers, then do a masterwindow first, otherwise just roll   */
  108. /****************************************************************************/
  109.  
  110. Multiple:
  111.  
  112.    Do i=0 to input.path.count-1
  113.       If Right(input.path.i,1)~=":" & Right(input.path.i,1)~="/" Then
  114.          input.path.i=input.path.i||"/"
  115.    End
  116.    If input.path.count=1 Then
  117.       Call ParseDrawer(input.path.0,'Main',input.all)
  118.    Else
  119.    Do
  120.       Maximum=0
  121.       NavneListe=''
  122.       Do i=0 to input.path.count-1
  123.          NavneListe=NavneListe||input.path.i||' '
  124.          If Length(input.path.i)>Maximum Then
  125.             Maximum=Length(input.path.i)
  126.       End
  127.       ItemListe=NavneListe
  128.       Call WriteLn('Master','')
  129.       Call AppendGuide(Maximum,,'Drawer')
  130.       Call WriteLn('Master','@EndNode')
  131.       Do i=0 to input.path.count-1
  132.          Call ParseDrawer(input.path.i,input.path.i,input.all)
  133.       End
  134.    End
  135. Return 0
  136.  
  137.  
  138. /****************************************************************************/
  139. /* Parse a whole drawer, including drawers and subdrawers                   */
  140. /****************************************************************************/
  141. ParseDrawer: Procedure Expose UseDT input.txt
  142.    Parse Arg skuffe,DrawerLevel,Recurs
  143.  
  144.    If DrawerLevel~='Main' Then
  145.       Call WriteLn('Master','@Node '||Compress(Skuffe,'/:'))
  146.    Call WriteLn('Master','')
  147.    Call WriteLn('Master','          '||Skuffe)
  148.    Call WriteLn('Master','')
  149.    Call MakeGuideList(skuffe)
  150.    If Recurs Then
  151.       Call MakeDrawerList(skuffe,Recurs)
  152.    Else
  153.       Call WriteLn('Master','@EndNode')
  154. Return 0
  155.  
  156.  
  157. /****************************************************************************/
  158. /* Make list over Guide's i drawer                                          */
  159. /****************************************************************************/
  160.  
  161. MakeGuideList: Procedure Expose UseDT input.txt
  162.    Parse Arg Drawer
  163.  
  164.    Code3='03'x
  165.    Count=1
  166.    MaxLength=0
  167.    NavneListe=''
  168.    ItemListe=''
  169.    Call Progress(Drawer)
  170.    Liste=MShowDir(Drawer,FILE)
  171.    Do While Count<=Words(Liste)
  172.       Item=Word(Liste,Count)
  173.       If Right(Item,5)~='.info' then
  174.       Do
  175.          If ~UseDT Then
  176.          Do
  177.             Call Open('Object',Drawer||StripM(Item),Read)
  178.             If ('@DATABASE ' = Upper(ReadCh('Object',10))) Then
  179.             Do
  180.                If Right(Upper(Item),6)='.GUIDE' Then
  181.                   Navn=Left(Item,Length(Item)-6)
  182.                Else
  183.                   Navn=Item
  184.                If Length(Navn)>MaxLength Then
  185.                   MaxLength=Length(Navn)
  186.                Navneliste=NavneListe||Navn||' '
  187.                ItemListe=ItemListe||Item||' '
  188.             End
  189.             Call Close('Object')
  190.          End
  191.          Else
  192.          Do
  193.             If Word(Statef(Drawer||StripM(Item)),2)>0 then
  194.             Do
  195.                Type=ExamineDT(Drawer||StripM(Item),,'VAR')
  196.                If Type='AmigaGuide'||'00'x | (input.txt & Type='ascii'||'00'x) Then
  197.                Do
  198.                   If Right(Upper(Item),6)='.GUIDE' Then
  199.                      Navn=Left(Item,Length(Item)-6)
  200.                   Else
  201.                      Navn=Item
  202.                   If Length(Navn)>MaxLength Then
  203.                      MaxLength=Length(Navn)
  204.                   If Type='AmigaGuide'||'00'x & input.txt Then
  205.                      Navn=Navn||Code3
  206.                   Navneliste=NavneListe||Navn||' '
  207.                   ItemListe=ItemListe||Item||' '
  208.                End
  209.             End
  210.          End
  211.       End
  212.       Count=Count+1
  213.    End
  214.    If Words(NavneListe)>0 Then
  215.       Call AppendGuide(MaxLength,Drawer,'GUIDE')
  216. Return 0
  217.  
  218.  
  219. /****************************************************************************/
  220. /* Append drawers in drawer to Guide                                        */
  221. /****************************************************************************/
  222.  
  223. MakeDrawerList: Procedure Expose UseDT input.txt
  224.    Parse Arg Skuffe,Recurs
  225.  
  226.    SkuffeListe=MShowDir(skuffe,DIR)
  227.    SkuffeListe2=''
  228.    If Words(SkuffeListe)=0 Then
  229.    Do
  230.       Call WriteLn('Master','@EndNode')
  231.       Return 0
  232.    End
  233.    MaxLength=0
  234.    Do i=1 to Words(skuffeliste)
  235.       If WordLength(skuffeliste,i)>MaxLength Then
  236.          MaxLength=WordLength(skuffeliste,i)
  237.       Skuffeliste2=Skuffeliste2||Skuffe||Word(Skuffeliste,i)||' '
  238.    End
  239.    Call WriteLn('Master','')
  240.    Call WriteLn('Master','          Skuffer:')
  241.    NavneListe=SkuffeListe
  242.    ItemListe=SkuffeListe2
  243.    Call AppendGuide(MaxLength,Skuffe,'DRAWER')
  244.    Call WriteLn('Master','@EndNode')
  245.    Do i=1 to Words(skuffeliste)
  246.       Call ParseDrawer(StripM(Word(SkuffeListe2,i))||'/',StripM(Word(SkuffeListe2,i))||'/',Recurs)
  247.    End
  248. Return 0
  249.  
  250.  
  251. /****************************************************************************/
  252. /* Put header on outputguide                                                */
  253. /****************************************************************************/
  254.  
  255. Header: Procedure
  256.    Parse Arg OutFile,HeaderFile
  257.  
  258.    Call Open('Master',Strip(OutFile),Write)
  259.    Call Open('Fil',Strip(HeaderFile),Read)
  260.    Do While ~eof('Fil')
  261.       Call Writeln('Master',ReadLn('Fil'))
  262.    End
  263.    Call Close('Fil')
  264. Return 0
  265.  
  266.  
  267. /****************************************************************************/
  268. /* Put guides from directory in output guide                                */
  269. /****************************************************************************/
  270.  
  271. AppendGuide: Procedure Expose NavneListe ItemListe UseDT input.txt
  272.    Parse Arg MLength,Skuffe,AppendType
  273.  
  274.    Code3='03'x
  275.    If Words(NavneListe)=0 Then
  276.       Return 0
  277.    Count=1
  278.    Call QuickSort(1,Words(NavneListe))
  279.    Soejler=Trunc(60/(MLength+2))
  280.    Spc=Copies(' ',trunc(60/soejler)-MLength)
  281.    Do While Count<=Words(NavneListe)
  282.       Linie='          '
  283.       Do i=1 to Soejler While Count<=Words(NavneListe)
  284.          If AppendType='GUIDE' Then
  285.             If Right(Word(NavneListe,Count),1)=Code3 Then
  286.                Linie=Linie||'@{@{b}'Left(StripM(Word(NavneListe,Count)),MLength,' ')'" Link "'Skuffe||StripM(Word(ItemListe,Count))||'/Main"@{ub}}'||Spc
  287.             Else
  288.                Linie=Linie||'@{"'Left(StripM(Word(NavneListe,Count)),MLength,' ')'" Link "'Skuffe||StripM(Word(ItemListe,Count))||'/Main"}'||Spc
  289.          Else
  290.             Linie=Linie||'@{"'Left(StripM(Word(NavneListe,Count)),MLength,' ')'" Link "'Compress(StripM(Word(ItemListe,Count)),'/:')||'"}'||Spc
  291.          Count=Count+1
  292.       End
  293.       Call Writeln('Master',Linie)
  294.    End
  295. Return 0
  296.  
  297.  
  298. /****************************************************************************/
  299. /* End of outputguide                                                       */
  300. /****************************************************************************/
  301.  
  302. EndGuide: Procedure
  303.    Parse Arg EndFile
  304.  
  305.    Call Open('Fil',Strip(EndFile),Read)
  306.    Do While ~eof('Fil')
  307.       Call Writeln('Master',ReadLn('Fil'))
  308.    End
  309.    Call Close('Fil')
  310.    Call Close('Master')
  311. Return 0
  312.  
  313.  
  314. /****************************************************************************/
  315. /* Prints Progress-report                                                   */
  316. /****************************************************************************/
  317.  
  318. Progress: Procedure
  319.    Parse Arg Drawer
  320.  
  321.    Say 'Examining 'Drawer
  322. Return 0
  323.  
  324.  
  325. /****************************************************************************/
  326. /* Replaces the builtin showdir, so filenames with ' ' are ok               */
  327. /****************************************************************************/
  328.  
  329. MShowdir: Procedure
  330.    Parse Arg Skuffe,Type
  331.  
  332.    Code1='01'x
  333.    Code2='02'x
  334.    Liste=ShowDir(Skuffe,Type,Code1)
  335.    Start=1
  336.    Do While Pos(' ',Liste,Start)~=0
  337.       Start=Pos(' ',Liste,Start)+1
  338.       Liste=OverLay(Code2,Liste,Start-1)
  339.    End
  340.    Start=1
  341.    Do While Pos(Code1,Liste,Start)~=0
  342.       Start=Pos(Code1,Liste,Start)+1
  343.       Liste=OverLay(' ',Liste,Start-1)
  344.    End
  345. Return Liste
  346.  
  347.  
  348. /****************************************************************************/
  349. /* Strips of the special code put in to save spaces in filenames            */
  350. /****************************************************************************/
  351.  
  352. StripM: Procedure
  353.    Parse Arg Ord
  354.  
  355.    Code2='02'x
  356.    Start=1
  357.    Do While Pos(Code2,Ord,Start)~=0
  358.       Start=Pos(Code2,Ord,Start)+1
  359.       Ord=OverLay(' ',Ord,Start-1)
  360.    End
  361. Return Ord
  362.  
  363.  
  364. /****************************************************************************/
  365. /* QuickSort of String                                                      */
  366. /****************************************************************************/
  367.  
  368. QuickSort: Procedure Expose NavneListe ItemListe
  369.    Parse Arg Venstre,Hoejre
  370.  
  371.    i=0
  372.    Sidste=0
  373.    If Venstre>=Hoejre Then
  374.       Return 0
  375.    Call Swap(Venstre,Trunc((Venstre + Hoejre)/2))
  376.    Sidste=Venstre
  377.    Do i=Venstre+1 to Hoejre
  378.       If Upper(StripM(Word(NavneListe,i))) < Upper(StripM(Word(NavneListe,Venstre))) Then
  379.       Do
  380.          Sidste=Sidste+1
  381.          Call Swap(Sidste,i)
  382.       End
  383.    End
  384.    Call Swap(Venstre,Sidste)
  385.    Call QuickSort(Venstre,Sidste-1)
  386.    Call QuickSort(Sidste+1,Hoejre)
  387. Return 0
  388.  
  389. Swap: Procedure Expose NavneListe ItemListe
  390.    Parse Arg LN,RN
  391.  
  392.    Temp=Word(NavneListe,LN)
  393.    NavneListe=Left(NavneListe,WordIndex(NavneListe,LN)-1)||' '||Word(NavneListe,RN)||Right(NavneListe,Length(NavneListe)-(WordIndex(NavneListe,LN)+WordLength(NavneListe,LN)-1))
  394.    NavneListe=Left(NavneListe,WordIndex(NavneListe,RN)-1)||' '||Temp||Right(NavneListe,Length(NavneListe)-(WordIndex(NavneListe,RN)+WordLength(NavneListe,RN)-1))
  395.    Temp=Word(ItemListe,LN)
  396.    ItemListe=Left(ItemListe,WordIndex(ItemListe,LN)-1)||' '||Word(ItemListe,RN)||Right(ItemListe,Length(ItemListe)-(WordIndex(ItemListe,LN)+WordLength(ItemListe,LN)-1))
  397.    ItemListe=Left(ItemListe,WordIndex(ItemListe,RN)-1)||' '||Temp||Right(ItemListe,Length(ItemListe)-(WordIndex(ItemListe,RN)+WordLength(ItemListe,RN)-1))
  398.    NavneListe=Space(NavneListe,1)
  399.    ItemListe=Space(ItemListe,1)
  400. Return 0
  401.  
  402.  
  403. /****************************************************************************/
  404. /* Control-C control                                                        */
  405. /****************************************************************************/
  406.  
  407. BREAK_C:
  408.    Say ('There there, easy now, I was in the middle of something here...')
  409.    Call Closeport('MasterGuide')
  410. Exit 10
  411.  
  412. SYNTAX:
  413.    Say ('The output file is currently in use!')
  414.    Call Closeport('MasterGuide')
  415. Exit 10
  416.